package com.qinggeng.project.system.controller;

import com.qinggeng.common.constant.UserConstants;
import com.qinggeng.common.utils.poi.ExcelUtil;
import com.qinggeng.framework.aspectj.lang.annotation.Log;
import com.qinggeng.framework.aspectj.lang.enums.BusinessType;
import com.qinggeng.framework.web.controller.BaseController;
import com.qinggeng.framework.web.domain.AjaxResult;
import com.qinggeng.framework.web.page.TableDataInfo;
import com.qinggeng.project.system.domain.UserWithdraw;
import com.qinggeng.project.system.service.IUserWithdrawService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户提现Controller
 *
 * @author qinggeng
 * @date 2020-06-30
 */
@RestController
@RequestMapping("/system/userWithdraw")
public class UserWithdrawController extends BaseController {
    @Autowired
    private IUserWithdrawService userWithdrawService;

    /**
     * 查询用户提现列表
     */
    @PreAuthorize("@ss.hasPermi('system:userWithdraw:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserWithdraw userWithdraw) {
        startPage();
        List<UserWithdraw> list = userWithdrawService.selectUserWithdrawList(userWithdraw);
        if (list.size() > 0) {
            for (UserWithdraw userWithdraw1 : list) {
                if (userWithdraw1.getAvatar() == null || userWithdraw1.getAvatar().equals("")) {
                    userWithdraw1.setAvatar(UserConstants.DEFAULT_AVATAR);
                }
            }
        }

        return getDataTable(list);
    }

    /**
     * 导出用户提现列表
     */
    @PreAuthorize("@ss.hasPermi('system:userWithdraw:export')")
    @Log(title = "用户提现", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(UserWithdraw userWithdraw) {
        List<UserWithdraw> list = userWithdrawService.selectUserWithdrawList(userWithdraw);
        ExcelUtil<UserWithdraw> util = new ExcelUtil<UserWithdraw>(UserWithdraw.class);
        return util.exportExcel(list, "userWithdraw");
    }

    /**
     * 获取用户提现详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:userWithdraw:query')")
    @GetMapping(value = "/{withdrawId}")
    public AjaxResult getInfo(@PathVariable("withdrawId") Long withdrawId) {
        return AjaxResult.success(userWithdrawService.selectUserWithdrawById(withdrawId));
    }

    /**
     * 新增用户提现
     */
    @PreAuthorize("@ss.hasPermi('system:userWithdraw:add')")
    @Log(title = "用户提现", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserWithdraw userWithdraw) {
        return toAjax(userWithdrawService.insertUserWithdraw(userWithdraw));
    }

    /**
     * 修改用户提现
     */
    @PreAuthorize("@ss.hasPermi('system:userWithdraw:edit')")
    @Log(title = "用户提现", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserWithdraw userWithdraw) {
        return toAjax(userWithdrawService.updateUserWithdraw(userWithdraw));
    }

    /**
     * 删除用户提现
     */
    @PreAuthorize("@ss.hasPermi('system:userWithdraw:remove')")
    @Log(title = "用户提现", businessType = BusinessType.DELETE)
    @DeleteMapping("/{withdrawIds}")
    public AjaxResult remove(@PathVariable Long[] withdrawIds) {
        return toAjax(userWithdrawService.deleteUserWithdrawByIds(withdrawIds));
    }
}
